<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorator="base/layout.html">


<!-- start: Content -->
<div layout:fragment="content" class="main ">

    <div class="row">
        <div class="col-lg-12">
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i><a th:href="@{../infoManage/indexTotal}">首页</a></li>
                <li><i class="fa fa-list-alt"></i><a th:href="@{../workInfo/queryWorkInfo}">企业信息管理</a></li>
                <li><i class="fa fa-indent"></i>修改企业信息</li>
            </ol>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-indent red"></i><strong>修改企业信息</strong></h2>
                </div>
                <div class="panel-body">
                    <form id="modularForm" action="" method="post" enctype="multipart/form-data"
                          class="form-horizontal ">
                        <input id="workInfoId" type="hidden" name="id" th:value="${workInfo.id}"/>


                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">承办部门</label>
                            <div class="col-md-2">
                                <select id="selectDepartment" name="departmentid" class="form-control" size="1"
                                        type="isNotSelectNull">

                                </select>
                                <span class="help-block">请选择承办部门(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">合作单位性质</label>
                            <div class="col-md-2">
                                <select id="selectUnitsNature" name="unitsnatureid" class="form-control" size="1"
                                        type="isNotSelectNull">

                                </select>
                                <span class="help-block">请选择合作单位性质(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="text-input">合作单位名称</label>
                            <div class="col-md-2">
                                <input type="text" name="unitscooperativename" class="form-control"
                                       th:value="${workInfo.unitscooperativename}" required>
                                <span class="help-block">请输入合作单位名称(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">企业类型</label>
                            <div class="col-md-2">
                                <select id="selectCooperativeType" name="cooperativetypeid" class="form-control"
                                        size="1" type="isNotSelectNull">

                                </select>
                                <span class="help-block">请选择企业类型(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">企业规模</label>
                            <div class="col-md-2">
                                <select id="selectScaleInfo" name="scaleid" class="form-control" size="1"
                                        type="isNotSelectNull">

                                </select>
                                <span class="help-block">请选择企业规模(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">外资属性</label>
                            <div class="col-md-2">
                                <select id="selectForeignProperty" name="foreignpropertyid" class="form-control"
                                        size="1" type="isNotSelectNull">

                                </select>
                                <span class="help-block">请选择外资属性(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">行政区属</label>
                            <div class="col-md-2">
                                <select id="selectAdministrativeDistrict" name="administrativedistrictid"
                                        class="form-control" size="1" type="isNotSelectNull">

                                </select>
                                <span class="help-block">请选择行政区属(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">企业所在地</label>
                            <div class="col-md-2">
                                <select id="selectEnterpriseLocation" name="enterpriselocationid" class="form-control"
                                        size="1" type="isNotSelectNull">

                                </select>
                                <span class="help-block">请选择企业所在地(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="text-input">企业联系人及联系方式</label>
                            <div class="col-md-2">
                                <input type="text" name="contactsname" class="form-control"
                                       th:value="${workInfo.contactsname}" required>
                                <span class="help-block">请输入企业联系人及联系方式(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">是否签署合作协议</label>
                            <div class="col-md-2">
                                <select name="signagreement" class="form-control" size="1" type="isNotSelectNull">
                                    <option value="-1">请选择</option>
                                    <option value="1" th:selected="${workInfo.signagreement == 1}">是</option>
                                    <option value="2" th:selected="${workInfo.signagreement == 2}">否</option>
                                </select>
                                <span class="help-block">请选择是否签署合作协议(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="date01">协议签署时间</label>
                            <div class="col-md-4">
                                <div class="input-group date col-sm-6">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" class="form-control date-picker" id="signagreement"
                                           name="signtime" readonly
                                           th:value="${#dates.format(workInfo.signtime,'yyyy-MM-dd')}" required>

                                </div>
                                <span class="help-block">请选择协议签署时间(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="date01">协议到期时间</label>
                            <div class="col-md-4">
                                <div class="input-group date col-sm-6">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" class="form-control date-picker" id="expirationTime"
                                           name="expirationtime" readonly
                                           th:value="${#dates.format(workInfo.expirationtime,'yyyy-MM-dd')}" required>

                                </div>
                                <span class="help-block">请选择协议到期时间(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="select">项目分类</label>
                            <div class="col-md-2">
                                <select id="selectProjectType" name="projecttypeid" class="form-control" size="1"
                                        type="isNotSelectNull">

                                </select>
                                <span class="help-block">请选择项目分类(必填)</span>
                            </div>
                        </div>

                        <div id="cooperativeContentDiv" th:if="${#lists.isEmpty(workInfo.cooperativeContentRelList)}">
                            <div class="form-group">
                                <label class="col-md-3 control-label">合作内容</label>


                                <div class="col-md-2">
                                    <select id="selectCooperativeContent"
                                            name="cooperativeContentRelList[0].cooperativecontentid"
                                            class="form-control" size="1" type="isNotSelectNull">

                                    </select>


                                    <span class="help-block">请选择合作内容(必填)</span>

                                </div>
                                <span class="col-md-1">
                                            <button type="button" class=" btn btn-sm btn-info"
                                                    onclick="addCooperativeContent()"> 添加</button>
                                    </span>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label">合作内容主要简介</label>
                                <div class="col-md-2">

                                    <input type="text" id="briefintroductionInput"
                                           name="cooperativeContentRelList[0].briefintroduction" class="form-control"
                                           placeholder="合作内容主要简介" required>
                                    <span class="help-block">请输入合作内容主要简介(必填)</span>
                                </div>
                            </div>

                        </div>


                        <div th:unless="${#lists.isEmpty(workInfo.cooperativeContentRelList)}"
                             th:each="cooperativeContentRel,state  : ${workInfo.cooperativeContentRelList}"
                             th:id="${'cooperativeContentDiv'+state.index}">

                            <div class="form-group">
                                <label class="col-md-3 control-label" for="text-input">合作内容</label>
                                <input th:id="${'cooperativeContentIdHidden'}" type="hidden"
                                       th:name="${'cooperativeContentRelList['+state.index+'].id'}"
                                       th:value="${cooperativeContentRel.id}"/>

                                <div class="col-md-2">
                                    <select th:id="${'selectCooperativeContent'+state.index}"
                                            th:name="${'cooperativeContentRelList['+state.index+'].cooperativecontentid'}"
                                            class="form-control" size="1" type="isNotSelectNull">

                                    </select>


                                    <span class="help-block">请选择合作内容</span>
                                </div>
                                <span class="col-md-1">
                                            <button type="button" class=" btn btn-sm btn-info"
                                                    onclick="addCooperativeContent()"> 添加</button>
                                        </span>

                            </div>


                            <div class="form-group">

                                <label class="col-md-3 control-label" for="text-input">合作内容主要简介</label>
                                <div class="col-md-2">
                                    <input type="text" id="briefintroductionInput"
                                           th:name="${'cooperativeContentRelList['+state.index+'].briefintroduction'}"
                                           class="form-control" th:value="${cooperativeContentRel.briefintroduction}"
                                           required>
                                    <span class="help-block">请输入合作内容主要简介(必填)</span>
                                </div>
                            </div>


                        </div>


                        <div id="workprogress" class="form-group">
                            <label class="col-md-3 control-label" for="text-input">本月工作进展情况</label>
                            <div class="col-md-2">
                                <input type="text" name="workprogress" class="form-control"
                                       th:value="${workInfo.workprogress}" required>
                                <span class="help-block">请输入本月工作进展情况(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="text-input">下一步工作计划</label>
                            <div class="col-md-2">
                                <input type="text" name="workplan" class="form-control" th:value="${workInfo.workplan}"
                                       required>
                                <span class="help-block">请输入下一步工作计划(必填)</span>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-md-3 control-label" for="text-input">阶段性工作成果</label>
                            <div class="col-md-2">
                                <input type="text" name="workresult" class="form-control"
                                       th:value="${workInfo.workresult}" required>
                                <span class="help-block">请输入阶段性工作成果(必填)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="text-input">部门联系人及联系方式</label>
                            <div class="col-md-2">
                                <input type="text" name="departmentContactName" class="form-control"
                                       th:value="${workInfo.departmentContactName}" required>
                                <span class="help-block">请输入部门联系人及联系方式(必填)</span>
                            </div>
                        </div>


                        <div id="agreementDiv" th:if="${#lists.isEmpty(workInfo.agreementurlList)}"
                             class="form-group">
                            <label class="col-md-3 control-label">合作协议</label>
                            <div class="col-md-2">
                                <input type="file" id="file-multiple-input" name="agreementUpload" multiple>

                            </div>

                            <span class="col-md-1">
                                    <button type="button" class=" btn btn-sm btn-info"
                                            onclick="addAgreementUrl()"> 添加</button>
                                </span>
                        </div>

                        <div th:unless="${#lists.isEmpty(workInfo.agreementurlList)}"
                             th:each="agreementurl,state  : ${workInfo.agreementurlList}"
                             class="form-group" th:id="${'agreementDiv'+state.index}">
                            <label class="col-md-3 control-label">合作协议</label>
                            <div th:id="${'agreementDivFile'+state.index}" class="col-md-3">

                                <a id="agreementurlName" th:href="@{downloadFile(fileName=${agreementurl})}"
                                   th:text="${agreementurl}"></a>
                            </div>
                            <span th:id="${'agreementDivSpan'+state.index}" class="col-md-1">
                                    <button type="button" class=" btn btn-sm btn-info"
                                            th:onclick="${'deleteAgreementUrl('+state.index+')'}"> 删除</button>
                                </span>

                            <span id="agreementDivAddSpan" th:if="${state.index==0}" class="col-md-1">
                                    <button type="button" class=" btn btn-sm btn-info"
                                            onclick="addAgreementUrl()"> 添加</button>
                                </span>
                        </div>


                        <div id="legalPersonCertificateDiv"
                             th:if="${#lists.isEmpty(workInfo.legalPersonCertificateURL)}"
                             class="form-group">
                            <label class="col-md-3 control-label">企业法人资质</label>
                            <div class="col-md-2">
                                <input type="file" name="legalPersonCertificateUpload" multiple>

                            </div>


                        </div>

                        <div th:unless="${#lists.isEmpty(workInfo.legalPersonCertificateURL)}"
                             class="form-group" id="legalPersonCertificateDiv">
                            <label class="col-md-3 control-label">企业法人资质</label>
                            <div id="legalPersonCertificateFileDiv" class="col-md-3">

                                <a th:href="@{downloadFile(fileName=${workInfo.legalPersonCertificateURL})}"
                                   th:text="${workInfo.legalPersonCertificateURL}"></a>
                            </div>
                            <span class="col-md-1">
                                    <button type="button" class=" btn btn-sm btn-info"
                                            th:onclick="${'deleteLegalPersonCertificate()'}"> 删除</button>
                                </span>


                        </div>


                        <div id="businessLicenseDiv" th:if="${#lists.isEmpty(workInfo.businessLicenseURL)}"
                             class="form-group">
                            <label class="col-md-3 control-label">企业营业执照</label>
                            <div class="col-md-2">
                                <input type="file" name="businessLicenseUpload" multiple>

                            </div>


                        </div>

                        <div th:unless="${#lists.isEmpty(workInfo.businessLicenseURL)}"
                             class="form-group" id="businessLicenseDiv">
                            <label class="col-md-3 control-label">企业营业执照</label>
                            <div id="businessLicenseFileDiv" class="col-md-3">

                                <a th:href="@{downloadFile(fileName=${workInfo.businessLicenseURL})}"
                                   th:text="${workInfo.businessLicenseURL}"></a>
                            </div>
                            <span class="col-md-1">
                                    <button type="button" class=" btn btn-sm btn-info"
                                            th:onclick="${'deleteBusinessLicense()'}"> 删除</button>
                                </span>


                        </div>


                        <div id="qualificationsDiv" th:if="${#lists.isEmpty(workInfo.qualificationsList)}">


                            <div class="form-group">
                                <label class="col-md-3 control-label">企业资质</label>
                                <div class="col-md-2">
                                    <input type="file" name="qualificationsList[0].qualificationsURLUpload" multiple>

                                </div>

                                <span class="col-md-1">
                                        <button type="button" class=" btn btn-sm btn-info"
                                                onclick="addQualifications()"> 添加</button>
                                    </span>
                            </div>


                            <div class="form-group">

                                <label class="col-md-3 control-label" for="text-input">企业资质名称</label>
                                <div class="col-md-2">
                                    <input type="text" id="qualificationsname"
                                           name="qualificationsList[0].qualificationsname" class="form-control">
                                    <span class="help-block">请输入企业资质名称</span>
                                </div>
                            </div>


                        </div>


                        <div th:unless="${#lists.isEmpty(workInfo.qualificationsList)}"
                             th:each="qualifications,state  : ${workInfo.qualificationsList}"
                             th:id="${'qualificationsDiv'+state.index}">

                            <div class="form-group">
                                <label class="col-md-3 control-label">企业资质</label>
                                <div th:id="${'qualificationsDivFile'+state.index}" class="col-md-3">
                                    <input th:id="${'qualificationsIdHidden'}" type="hidden"
                                           th:name="${'qualificationsList['+state.index+'].id'}"
                                           th:value="${qualifications.id}"/>

                                    <a id="qualificationsFileName"
                                       th:href="@{downloadFile(fileName=${qualifications.qualificationsurl})}"
                                       th:text="${qualifications.qualificationsurl}"></a>
                                </div>
                                <span th:id="${'qualificationsDivSpan'+state.index}" class="col-md-1">
                                    <button type="button" class=" btn btn-sm btn-info"
                                            th:onclick="${'deleteQualificationsUrl('+state.index+')'}"> 删除</button>
                                    </span>

                                <span id="qualificationsDivAddSpan" th:if="${state.index==0}" class="col-md-1">
                                        <button type="button" class=" btn btn-sm btn-info"
                                                onclick="addQualifications()"> 添加</button>
                                    </span>
                            </div>


                            <div class="form-group">

                                <label class="col-md-3 control-label" for="text-input">企业资质名称</label>
                                <div class="col-md-2">
                                    <input type="text" id="qualificationsname"
                                           th:name="${'qualificationsList['+state.index+'].qualificationsname'}"
                                           class="form-control" th:value="${qualifications.qualificationsname}">
                                    <span class="help-block">请输入企业资质名称</span>
                                </div>
                            </div>


                        </div>


                        <div id="remarkDiv" class="form-group">
                            <label class="col-md-3 control-label" for="text-input">备注</label>
                            <div class="col-md-2">
                                <input type="text" id="text-input" name="remark" class="form-control"
                                       th:value="${workInfo.remark}">
                                <span class="help-block">相关需求、建议等</span>
                            </div>
                        </div>
                        <br>

                </div>
                <div class="panel-footer">
                    <button id="submitBtn" type="submit" class="btn btn-sm btn-success"><i
                            class="fa fa-dot-circle-o"></i> 保存
                    </button>
                    <button type="button" class="btn btn-sm btn-success" onclick="history.back()"><i
                            class="fa fa-dot-circle-o"></i> 返回
                    </button>
                </div>
                </form>
            </div>
        </div>


    </div><!--/.row-->


    <script th:inline="javascript" type="text/javascript">


        $(document).ready(function () {

            //加载承办部门
            initDepartment();
            //加载行政区属
            initAdministrativeDistrict();
            //加载企业所在地
            initEnterpriseLocation();

            //加载合作单位性质
            initUnitsNature();

            //加载企业类型
            initCooperativeType();

            //加载企业规模
            initScale();

            //加载外资属性
            initForeignProperty();

            //加载时间控件
            setDatePicker("#signagreement");

            //加载时间控件
            setDatePicker("#expirationTime");

            //加载项目分类
            initProjectType();


            //加载合作内容
            initCooperativeContent();
        })

        //法人资质删除
        function deleteLegalPersonCertificate() {
            /**
             * 物理删除  数据库中企业法人资质
             * 添加确认删除按钮提示框
             *
             */

            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                //确认
                //首先关闭弹窗
                layer.close(index);

                //获取workInfo主键id
                var id = $("#workInfoId").val();


                $.ajax({
                    url: 'deleteLegalPersonCertificate',
                    type: 'get',
                    dataType: 'json',
                    data: {id: id},
                    success: function (data) {

                        //删除成功
                        $('#legalPersonCertificateFileDiv').html("<input type='file' name='legalPersonCertificateUpload' multiple>");


                    }
                })


            }, function () {
                //取消

            });
        }

        //营业执照删除
        function deleteBusinessLicense() {
            /**
             * 物理删除  数据库中营业执照资质
             * 添加确认删除按钮提示框
             *
             */

            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                //确认
                //首先关闭弹窗
                layer.close(index);

                //获取workInfo主键id
                var id = $("#workInfoId").val();


                $.ajax({
                    url: 'deleteBusinessLicense',
                    type: 'get',
                    dataType: 'json',
                    data: {id: id},
                    success: function (data) {

                        //删除成功
                        $('#businessLicenseFileDiv').html("<input type='file' name='businessLicenseUpload' multiple>");


                    }
                })


            }, function () {
                //取消

            });
        }

        //修改协议到期时间判断提示字段
        $("#submitBtn").click(function () {
            var time = $("#expirationTime").val();
            var endDate = new Date(time);
            var myDate = new Date();
            //获取下个月
            var month = myDate.getMonth() + 1;
            //获取当前年
            var year = myDate.getFullYear();
            //获取当前日
            var date = myDate.getDate();
            var nextMonth = year + '-' + month + "-" + date;
            var nextMonthDate = new Date(nextMonth)
            var id = $("#workInfoId").val();
            if (endDate > nextMonthDate) {
                $.ajax({
                    url: 'eliminateReminding',
                    type: 'get',
                    data: 'id=' + id,
                    success: function () {
                    }
                })
            }
        });


        //加载承办部门
        function initDepartment() {

            //获取部门id
            var departmentid = [[${workInfo.departmentid}]];

            $("#selectDepartment").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../department/selectDepartmentInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    //如果部门id是空
                    if (departmentid == undefined || departmentid == null || departmentid == "") {
                        for (var i in data) {

                            $("#selectDepartment").append("<option value=" + data[i].id + ">" + data[i].department + "</option>");

                        }
                    }
                    else {
                        for (var i in data) {
                            if (departmentid == data[i].id) {

                                $("#selectDepartment").append("<option value=" + data[i].id + " selected>" + data[i].department + "</option>");
                            }
                            else {
                                $("#selectDepartment").append("<option value=" + data[i].id + ">" + data[i].department + "</option>");
                            }

                        }
                    }


                }
            })


        }

        //加载行政区属
        function initAdministrativeDistrict() {
            var administrativedistrictid = [[${workInfo.administrativedistrictid}]];
            $("#selectAdministrativeDistrict").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../administrativeDistrict/SelectAdministrativeDistrictInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    if (administrativedistrictid == undefined || administrativedistrictid == null || administrativedistrictid == "") {
                        for (var i in data) {
                            $("#selectAdministrativeDistrict").append("<option value=" + data[i].id + ">" + data[i].administrativedistrict + "</option>");
                        }
                    } else {
                        for (var i in data) {
                            if (administrativedistrictid == data[i].id) {
                                $("#selectAdministrativeDistrict").append("<option value=" + data[i].id + " selected>" + data[i].administrativedistrict + "</option>")
                            } else {
                                $("#selectAdministrativeDistrict").append("<option value=" + data[i].id + ">" + data[i].administrativedistrict + "</option>")
                            }
                        }
                    }
                }
            })
        }

        //加载企业所在地
        function initEnterpriseLocation() {
            var enterpriselocationid = [[${workInfo.enterpriselocationid}]];
            $("#selectEnterpriseLocation").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../enterpriseLocation/SelectEnterpriseLocationInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    if (enterpriselocationid == undefined || enterpriselocationid == null || enterpriselocationid == "") {
                        for (var i in data) {
                            $("#selectEnterpriseLocation").append("<option value=" + data[i].id + ">" + data[i].enterpriselocation + "</option>");
                        }
                    } else {
                        for (var i in data) {
                            if (enterpriselocationid == data[i].id) {
                                $("#selectEnterpriseLocation").append("<option value=" + data[i].id + " selected>" + data[i].enterpriselocation + "</option>")
                            } else {
                                $("#selectEnterpriseLocation").append("<option value=" + data[i].id + ">" + data[i].enterpriselocation + "</option>")
                            }
                        }
                    }
                }
            })

        }

        //加载合作单位性质
        function initUnitsNature() {

            //获取合作单位性质id
            var unitsnatureid = [[${workInfo.unitsnatureid}]];

            $("#selectUnitsNature").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../unitsNature/selectUnitsNatureInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (unitsnatureid == undefined || unitsnatureid == null || unitsnatureid == "") {
                        for (var i in data) {
                            $("#selectUnitsNature").append("<option value=" + data[i].id + ">" + data[i].name + "</option>");
                        }
                    }
                    else {
                        for (var i in data) {

                            if (unitsnatureid == data[i].id) {
                                $("#selectUnitsNature").append("<option value=" + data[i].id + " selected>" + data[i].name + "</option>");
                            }
                            else {

                                $("#selectUnitsNature").append("<option value=" + data[i].id + ">" + data[i].name + "</option>");

                            }
                        }
                    }


                }
            })

        }

        //加载企业类型
        function initCooperativeType() {

            var cooperativetypeid = [[${workInfo.cooperativetypeid}]];

            $("#selectCooperativeType").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../cooperativeType/selectCooperativeTypeInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (cooperativetypeid == undefined || cooperativetypeid == null || cooperativetypeid == "") {
                        for (var i in data) {
                            $("#selectCooperativeType").append("<option value=" + data[i].id + ">" + data[i].type + "</option>");
                        }
                    }
                    else {
                        for (var i in data) {
                            if (cooperativetypeid == data[i].id) {
                                $("#selectCooperativeType").append("<option value=" + data[i].id + " selected>" + data[i].type + "</option>");
                            }
                            else {
                                $("#selectCooperativeType").append("<option value=" + data[i].id + ">" + data[i].type + "</option>");
                            }


                        }
                    }

                }
            })

        }

        //加载企业规模
        function initScale() {

            var scaleid = [[${workInfo.scaleid}]];

            $("#selectScaleInfo").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../scale/selectScaleInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (scaleid == undefined || scaleid == null || scaleid == "") {
                        for (var i in data) {
                            $("#selectScaleInfo").append("<option value=" + data[i].id + ">" + data[i].scale + "</option>");
                        }
                    }
                    else {
                        for (var i in data) {

                            if (scaleid == data[i].id) {
                                $("#selectScaleInfo").append("<option value=" + data[i].id + " selected>" + data[i].scale + "</option>");
                            }
                            else {
                                $("#selectScaleInfo").append("<option value=" + data[i].id + ">" + data[i].scale + "</option>");
                            }


                        }
                    }


                }
            })

        }

        //加载外资属性
        function initForeignProperty() {

            var foreignpropertyid = [[${workInfo.foreignpropertyid}]];

            $("#selectForeignProperty").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../foreignProperty/selectForeignPropertyInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (foreignpropertyid == undefined || foreignpropertyid == null || foreignpropertyid == "") {
                        for (var i in data) {

                            $("#selectForeignProperty").append("<option value=" + data[i].id + ">" + data[i].property + "</option>");
                        }

                    }
                    else {
                        for (var i in data) {
                            if (foreignpropertyid == data[i].id) {
                                $("#selectForeignProperty").append("<option value=" + data[i].id + " selected>" + data[i].property + "</option>");
                            }
                            else {

                                $("#selectForeignProperty").append("<option value=" + data[i].id + ">" + data[i].property + "</option>");

                            }
                        }
                    }

                }
            })

        }

        //加载项目分类
        function initProjectType() {

            var projecttypeid = [[${workInfo.projecttypeid}]];

            $("#selectProjectType").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../projectType/selectProjectTypeInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (projecttypeid == undefined || projecttypeid == null || projecttypeid == "") {
                        for (var i in data) {

                            $("#selectProjectType").append("<option value=" + data[i].id + ">" + data[i].projecttype + "</option>");
                        }

                    }
                    else {
                        for (var i in data) {
                            if (projecttypeid == data[i].id) {
                                $("#selectProjectType").append("<option value=" + data[i].id + " selected>" + data[i].projecttype + "</option>");
                            }
                            else {

                                $("#selectProjectType").append("<option value=" + data[i].id + ">" + data[i].projecttype + "</option>");
                            }
                        }

                    }


                }
            })

        }

        //加载合作内容
        function initCooperativeContent() {

            var cooperativeContentRelList = [[${workInfo.cooperativeContentRelList}]];

            $.ajax({
                url: '../cooperativeContent/selectCooperativeContentList',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    //当数据库中没有合作内容时，展示新的合作内容下拉框
                    if (cooperativeContentRelList == undefined || cooperativeContentRelList == null || cooperativeContentRelList == "") {
                        $("#selectCooperativeContent").append("<option value=-1>请选择</option>");
                        for (var i in data) {

                            $("#selectCooperativeContent").append("<option value=" + data[i].id + ">" + data[i].content + "</option>");
                        }
                    }
                    //数据库有合作内容时，展示已经保存的合作内容下拉框
                    else {

                        for (var x in cooperativeContentRelList) {
                            $("#selectCooperativeContent" + x).append("<option value=-1>请选择</option>");

                            //重新编辑按钮，除了第一个按钮是添加外，其他都是删除按钮
                            if (x != 0) {

                                //数据库真删，加删除确认框
                                $("#cooperativeContentDiv" + x).find("button").html("删除").attr("onclick", "deleteCooperativeContent('cooperativeContentDiv" + x + "')");
                            }

                            for (var i in data) {

                                if (cooperativeContentRelList[x].cooperativecontentid == data[i].id) {
                                    $("#selectCooperativeContent" + x).append("<option value=" + data[i].id + " selected>" + data[i].content + "</option>");
                                }
                                else {

                                    $("#selectCooperativeContent" + x).append("<option value=" + data[i].id + ">" + data[i].content + "</option>");
                                }
                            }
                        }


                    }


                }
            })

        }

        //删除后台数据库合作内容
        function deleteCooperativeContent(cooperativeContentDivName) {
            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                //确认
                //首先关闭弹窗
                layer.close(index);


                $.ajax({
                    url: 'deleteCooperativeContentRel',
                    type: 'get',
                    dataType: 'json',
                    data: {id: $("#" + cooperativeContentDivName).find("#cooperativeContentIdHidden").val()},
                    success: function (data) {
                        $("#" + cooperativeContentDivName).remove();
                    }
                })


            }, function () {
                //取消

            });


        }

        //合作内容个数计数
        var num = 0;

        var cooperativeContentRelList = [[${workInfo.cooperativeContentRelList}]];

        if (cooperativeContentRelList == undefined || cooperativeContentRelList == null || cooperativeContentRelList == "") {
            num = 0;
        }
        else {
            num = cooperativeContentRelList.length;
        }

        //添加合作内容按钮
        function addCooperativeContent() {

            var cooperativeContentRelList = [[${workInfo.cooperativeContentRelList}]];
            //合作内容是空
            if (cooperativeContentRelList == undefined || cooperativeContentRelList == null || cooperativeContentRelList == "") {


                num += 1;
                var addItem = $('#cooperativeContentDiv').clone(true);
                $(addItem).find("button").html("删除").attr("onclick", "javascript:$(this.parentNode.parentNode.parentNode).remove();");
                $(addItem).find("select").attr("name", "cooperativeContentRelList[" + num + "].cooperativecontentid");
                $(addItem).find("#briefintroductionInput").attr("name", "cooperativeContentRelList[" + num + "].briefintroduction").val("");

                $('#workprogress').before(addItem);


            }
            //合作内容不是空
            else {

                var addItem = $('#cooperativeContentDiv0').clone(true).attr("id", "cooperativeContentDiv" + num);
                //新添加的合作内容没有主键id
                $(addItem).find("#cooperativeContentIdHidden").remove();
                $(addItem).find("button").html("删除").attr("onclick", "javascript:$(this.parentNode.parentNode.parentNode).remove();");
                $(addItem).find("select").attr("name", "cooperativeContentRelList[" + num + "].cooperativecontentid").val("-1");
                $(addItem).find("#briefintroductionInput").attr("name", "cooperativeContentRelList[" + num + "].briefintroduction").val("");
                $('#workprogress').before(addItem);

                num += 1;


            }
        }


        //添加合作协议按钮
        function addAgreementUrl() {

            var agreementurlList = [[${workInfo.agreementurlList}]];
            if (agreementurlList == undefined || agreementurlList == null || agreementurlList == "") {
                var addItem = $('#agreementDiv').clone(true);
                $(addItem).find("button").html("删除").attr("onclick", "javascript:$(this.parentNode.parentNode).remove();");
                $(addItem).find("input").val("");
                $('#legalPersonCertificateDiv').before(addItem);

            }
            else {
                var addItem = $('#agreementDiv0').clone(true);
                //变成空文件
                $(addItem).find("div").html("<input type='file' id='file-multiple-input' name='agreementUpload' multiple>");
                //删除添加按钮层
                $(addItem).find("#agreementDivAddSpan").html("")
                //添加删除按钮层
                $(addItem).find("#agreementDivSpan0").html("<button type='button' class='btn btn-sm btn-info' onclick='javascript:$(this.parentNode.parentNode).remove();' > 删除</button>");
                $('#legalPersonCertificateDiv').before(addItem);
            }


        }

        //删除合作协议按钮
        function deleteAgreementUrl(deleteNum) {

            /**
             * 物理删除  数据库中，合作协议文件名。修改数据库字段
             * 添加确认删除按钮提示框
             *
             */

            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                //确认
                //首先关闭弹窗
                layer.close(index);

                //获取workInfo主键id
                var id = $("#workInfoId").val();

                //获取要删除的文件名
                var deleteAgreementurlName = $("#agreementDiv" + deleteNum).find("#agreementurlName").html();


                $.ajax({
                    url: 'deleteAgreementurlName',
                    type: 'get',
                    dataType: 'json',
                    data: {id: id, deleteAgreementurlName: deleteAgreementurlName},
                    success: function (data) {

                        //删除成功
                        //第一个合作协议
                        if (deleteNum == 0) {
                            //将a标签变为File标签
                            $('#agreementDivFile0').html("<input type='file' id='file-multiple-input' name='agreementUpload' multiple>");
                            //删除删除按钮层
                            $('#agreementDivSpan0').html("");


                        }
                        //其他合作协议层
                        else {
                            $('#agreementDiv' + deleteNum).remove();
                        }


                    }
                })


            }, function () {
                //取消

            });


        }


        //企业资质个数计数
        var qualificationsNum = 0;

        var qualificationsList = [[${workInfo.qualificationsList}]];

        if (qualificationsList == undefined || qualificationsList == null || qualificationsList == "") {
            qualificationsNum = 0;
        }
        else {
            qualificationsNum = qualificationsList.length;
        }


        //添加企业资质按钮
        function addQualifications() {

            var qualificationsList = [[${workInfo.qualificationsList}]];
            if (qualificationsList == undefined || qualificationsList == null || qualificationsList == "") {

                qualificationsNum += 1;
                var addItem = $('#qualificationsDiv').clone(true);
                $(addItem).find("button").html("删除").attr("onclick", "javascript:$(this.parentNode.parentNode.parentNode).remove();");
                $(addItem).find("input[type='file']").val("");
                $(addItem).find("input[type='file']").attr("name", "qualificationsList[" + qualificationsNum + "].qualificationsURLUpload");
                $(addItem).find("input[type='text']").val("");
                $(addItem).find("input[type='text']").attr("name", "qualificationsList[" + qualificationsNum + "].qualificationsname");


                $('#remarkDiv').before(addItem);

            }
            else {


                var addItem = $('#qualificationsDiv0').clone(true).attr("id", "qualificationsDiv" + qualificationsNum);

                //新添加的企业资质没有主键id
                $(addItem).find("#qualificationsIdHidden").remove();
                //变成空文件
                $(addItem).find("#qualificationsDivFile0").html("<input type='file' name='qualificationsList[" + qualificationsNum + "].qualificationsURLUpload' multiple>");
                //删除添加按钮层
                $(addItem).find("#qualificationsDivAddSpan").html("")
                //添加删除按钮层
                $(addItem).find("#qualificationsDivSpan0").html("<button type='button' class='btn btn-sm btn-info' onclick='javascript:$(this.parentNode.parentNode.parentNode).remove();' > 删除</button>");

                $(addItem).find("#qualificationsname").attr("name", "qualificationsList[" + qualificationsNum + "].qualificationsname").val("");
                $('#remarkDiv').before(addItem);

                qualificationsNum += 1;
            }


        }

        //删除企业资质按钮
        function deleteQualificationsUrl(deleteNum) {

            /**
             * 物理删除  数据库中企业资质
             * 添加确认删除按钮提示框
             *
             */

            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                //确认
                //首先关闭弹窗
                layer.close(index);


                $.ajax({
                    url: 'deleteQualifications',
                    type: 'get',
                    dataType: 'json',
                    data: {id: $("#qualificationsDiv" + deleteNum).find("#qualificationsIdHidden").val()},
                    success: function (data) {

                        //删除成功
                        //第一个合作协议
                        if (deleteNum == 0) {
                            //将a标签变为File标签
                            $('#qualificationsDivFile0').html("<input type='file'  name='qualificationsList[0].qualificationsURLUpload' multiple>");
                            //删除删除按钮层
                            $('#qualificationsDivSpan0').html("");
                            //清空资质名称
                            $("#qualificationsDiv" + deleteNum).find("#qualificationsname").val("")


                        }
                        //其他合作协议层
                        else {
                            $('#qualificationsDiv' + deleteNum).remove();
                        }


                    }
                })


            }, function () {
                //取消

            });


        }


        $("#modularForm").validate({

            submitHandler: function (form) {

                $('#modularForm').ajaxSubmit(      //ajax方式提交表单
                    {
                        url: 'workInfoUpdate',
                        type: 'post',
                        success: function (data) {
                            layer.msg("修改成功");
                            setTimeout(function () {
                                window.location = ("queryWorkInfo")
                            }, 1500);
                        }
                        //clearForm: false,//禁止清楚表单
                        //resetForm: false //禁止重置表单
                    });
            }
        })


    </script>


</div>
<!-- end: Content -->

